<template>
  <div>
    <m-head title="我的课程"></m-head>
    <div class="list" v-if="list.length>0">
      <ul>
        <li v-for="(item, index) in list" v-bind:key="index" @click="$router.push({path:'/contentlist',query:{id:item.course.id, isMine: true}})">
          <img :src="item.course.cover" alt="">
          <span>{{item.course.name}}</span>
        </li>
      </ul>
    </div>
    <div v-else>
      <p class="else">你还没有购买课程记录！</p>
    </div>
  </div>
</template>

<script>
import MHead from './MHeader'
import * as user from '../api/user'
export default {
  name: 'my-course',
  components: {
    'm-head': MHead
  },
  data () {
    return {
      page: 1,
      list: [
      ]
    }
  },
  mounted () {
    this.getList({})
  },
  methods: {
    getList () {
      user.myCourses()
        .then(res => {
          console.log(res.data)
          this.list = this.list.concat(res.data)
      })
    }
  }
}
</script>

<style scoped>
  .list{
    padding: 0 0 .3rem;
  }
  .list ul{
    border-top: 1px solid #ddd;
  }
  .list li{
    border-bottom: 1px solid #ddd;
    padding: 0 .2rem;
    display: flex;
    align-items: center;
    height: 1.4rem;
  }
  .list li img{
    width: .8rem;
    flex-shrink: 0;
    margin-right: .2rem;
  }
  .list li span{
    font-size: .42rem;
    color: #000;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    flex-grow: 1;
  }
  .else{
    margin: 2rem auto;
    font-size: .42rem;
    color: #333;
    text-align: center;
  }
</style>
